#!/bin/bash

#进入安装目录的 conf/ 目录下，拷贝配置样本并进行修改
source /etc/profile
ZOOKEEPER_CONF=${ZOOKEEPER_HOME}/conf

#移动文件
cp ${ZOOKEEPER_CONF}/zoo_sample.cfg  ${ZOOKEEPER_CONF}/zoo.cfg

## 修改以下内容

sed -i "s@^dataDir=.*@dataDir=${ZOOKEEPER_HOME}/data@" ${ZOOKEEPER_CONF}/zoo.cfg

##  配置集群：1、2、3为后面myid文件中的内容，node01要与该文件所对应的主机名一致

hosts=($(cat /etc/hosts | grep -Ev "(^$|^#|localhost)" | awk '{print $2}'))

for ((i=1;i<=${#hosts[@]};i++))
do
 sed -i "$ a server.$i=${hosts[i-1]}:2287:3387" ${ZOOKEEPER_CONF}/zoo.cfg
done

# 标识节点
mkdir -vp  ${ZOOKEEPER_HOME}/data
number=$(hostname| grep -Eo "([1-9]+)")
echo "$number" > ${ZOOKEEPER_HOME}/data/myid

echo -e "spark配置文件已加载!!!!!!!!!!!!!!!!!!!!!!!!"
